#!/bin/sh -e

export LDFLAGS="$LDFLAGS -static"

# Samurai is faster than make, so we prefer using it instead if available
if cpt l -q samurai; then
    cat - ninja.in <<EOF> build.ninja
destdir = $1
cc = ${CC:-cc}
cflags = -std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter $CFLAGS
ldflags = -static $LDFLAGS
EOF
    ninja
    ninja install
else
    make PREFIX=/usr LDFLAGS="$LDFLAGS"
    make PREFIX=/usr DESTDIR="$1" install
fi

ln -s samu   "$1/usr/bin/ninja"
ln -s samu.1 "$1/usr/share/man/man1/ninja.1"
